package com.yiyuan.common.util;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUitl {
	public void send() {
		try {
			String title = "测试邮箱";
			//String server163 = "smtp.163.com";
			String serverSohu = "smtp.sohu.net";
			title = new String(title.getBytes("iso-8859-1"));
			Properties props = new Properties();
			props.put("mail.smtp.host", serverSohu);// 指定SMTP服务器
			props.put("mail.smtp.auth", "true");// 指定是否需要SMTP验证

			Session mailSession = Session.getDefaultInstance(props);

			mailSession.setDebug(true);// 是否在控制台显示debug信息
			Message message = new MimeMessage(mailSession);
			message.setFrom(new InternetAddress("k445546363@sohu.com"));// 发件人
			message.addRecipient(Message.RecipientType.TO, new InternetAddress("linhe_150@163.com"));// 收件人
			message.setSubject(title);// 邮件主题
			message.setText(title);// 邮件内容
			message.saveChanges();

			Transport transport = mailSession.getTransport("smtp");
			transport.connect(serverSohu, "k44556363", "jiangsu"); // 这个邮箱可随便使用
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();

		} catch (MessagingException m) {
			System.out.println(m.toString());
		} catch (UnsupportedEncodingException m) {
			System.out.println(m.toString());
		}
	}
}
